<template>
  <div class="my-follows">
    <div class="my-follows-main">
      <div class="my-follows-hd-box">
        <h1 class="my-follows-hd">我的关注（{{ foTotal }}）</h1>
      </div>
      <ul class="my-follows-ul">
        <li class="my-follows-item" v-for="item in follows" :key="item.userId">
          <s-user :item="item"></s-user>
        </li>
      </ul>
    </div>
    <div class="follows-el-pagination" v-if="foTotal > 30">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="30"
        layout="prev, pager, next, jumper"
        :total="foTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import SUser from "components/user/SUser";
export default {
  components: {
    SUser,
  },
  props: {
    foTotal: {
      type: Number,
      default() {
        return 0;
      },
    },
  },
  data() {
    return {
      id: 0,
      follows: [],
      currentPage: 1,
    };
  },
  mounted() {
    if (this.$store.state.profile.userId) {
      this.id = this.$store.state.profile.userId;
      this.getFollows();
    } else {
      this.getLoginStatus();
    }
  },
  methods: {
    getLoginStatus() {
      // 获取登录状态
      this.axios({
        url: "/login/status?timerstamp=" + Date.now(),
      })
        .then((res) => {
          this.$store.state.profile = res.data.data.profile;
          this.id = res.data.data.profile.userId;
          this.getFollows();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleCurrentChange() {
      this.getFollows();
      // 点击分页后，滚动到评论的头部，141为页面头部组件的高度
      this.$emit("pScroll", 0);
    },
    getFollows() {
      this.axios({
        url:
          "/user/follows?uid=" +
          this.id +
          "&offset=" +
          (this.currentPage - 1) * 30,
      })
        .then((res) => {
          this.follows = res.data.follow;
          console.log(this.follows);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.my-follows {
  padding: 0 10px;
}
.my-follows .my-follows-main {
  position: relative;
}
.my-follows .my-follows-main .my-follows-hd-box {
  height: 45px;
  border-bottom: 4px solid var(--color-theme);
}
.my-follows .my-follows-main .my-follows-hd {
  display: block;
  margin: 0;
  font-size: 24px;
  font-weight: 400;
}
.my-follows .my-follows-item {
  position: relative;
  height: 100px;
  padding: 10px 0;
  overflow: hidden;
  border-bottom: 1px solid #999;
}
.follows-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto 0;
}
</style>